#!/bin/bash
udp_server() {
    for orbital in {11..11}; do
        for id in {03..06}; do
            node="s${orbital}${id}"
            ip="192.168.${orbital}.${id#0}"     # 去掉末尾的0
            port="1${orbital}${id}"
            docker exec ${node} bash -c "server --ip=${ip} --port=${port} > ~/logfile/server/${node}.log 2>&1 &"
        done
    done
    # kill -9 $(ps ux | grep -i '\bserver --ip' | awk '{print $2}')
}

udp_client() {
    bandwidth=30000   #kbps
    for orbital0 in {11..11}; do
        for id0 in {01..01}; do
            srcip="192.168.${orbital0}.1"
            node="s${orbital0}01"

            for orbital in {11..11}; do
                for id in {03..06}; do
                    dstip="192.168.${orbital}.${id#0}"
                    dstport="1${orbital}${id}"
                    if [ ${srcip} = ${dstip} ]
                    then
                        continue
                    fi
                    docker exec ${node} bash -c "client --srcip=${srcip} --dstip=${dstip} --dstport=${dstport} -n 0 -t 2 -s 1400 -b ${bandwidth}  > /dev/null 2>&1 &"
                done
            done

        done
    done22

    # kill -9 $(ps ux | grep -i '\client --srcip' | awk '{print $2}')
}

udp_server
udp_client